//
//  html2String.swift
//  jmwebseoApp1803
//
//  Created by YQ05 on 2018/4/11.
//  Copyright © 2018年 YQ05. All rights reserved.
//

import Foundation

//extension String {
//    var html2AttributedString: NSAttributedString? {
//        do {
////           return try NSAttributedString(data: Data(utf8), options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
//            return try NSAttributedString(data: Data(utf8), options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
//        } catch  {
//            print(error)
//            return nil
//        }
//    }
//    var html2String:String {
//        return html2AttributedString?.string ?? ""
//    }
//}



extension String {
    var html2AttributedString: NSAttributedString? {
        do {
            return try NSAttributedString(data: Data(utf8),
                                          options: [.documentType: NSAttributedString.DocumentType.html,
                                                    .characterEncoding: String.Encoding.utf8.rawValue],
                                          documentAttributes: nil)
        } catch {
            print("error: ", error)
            return nil
        }
    }
    var html2String: String {
        return html2AttributedString?.string ?? ""
    }
}



